package jinyilw.swing.visuals.Icomp;

import jinyilw.swing.i18n.ICSetting;
import jinyilw.swing.rlaf.theme.RThemeColor;

import javax.swing.Icon;
import javax.swing.plaf.UIResource;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;

public class IRichWrapLabel extends IWrapLabel
{
	private static final long serialVersionUID = -7120460620805293701L;
	private float leftX = 0, leftY = 0, rightX = 1, rightY = 1;
	private Color leftColor, rightColor;
	private boolean autoShadow = true;

	public IRichWrapLabel()
	{
	}

	public IRichWrapLabel(String text)
	{
		super(text);
	}

	public IRichWrapLabel(String longText, int wrapWidth)
	{
		super(longText, wrapWidth);
	}

	public IRichWrapLabel(String longText, int wrapWidth, Font font)
	{
		super(longText, wrapWidth, font);
	}

	public IRichWrapLabel(ICSetting iSetting)
	{
		super(iSetting);
	}

	public IRichWrapLabel(ICSetting iSetting, int wrapWidth)
	{
		super(iSetting, wrapWidth);
	}

	public IRichWrapLabel(ICSetting iSetting, int wrapWidth, Font font)
	{
		super(iSetting, wrapWidth, font);
	}

	public IRichWrapLabel(ICSetting iSetting, Icon icon,
			int horizontalAlignment)
	{
		super(iSetting, icon, horizontalAlignment);
	}

	public void setLeftShadow(float x, float y, Color color)
	{
		leftX = x;
		leftY = y;
		leftColor = color;
	}

	public void setRightShadow(float x, float y, Color color)
	{
		rightX = x;
		rightY = y;
		rightColor = color;
		autoShadow = false;
	}

	public void setAutoShadow(boolean b)
	{
		autoShadow = b;
	}

	@Override
	public void setFont(Font font)
	{
		if (font == null || font.equals(getFont()))
			return;
		if (autoShadow)
		{
			float fontSize = font.getSize();
			if (fontSize > 12)
				rightY = rightX = fontSize / 15;
			else
				rightY = rightX = 0.8f;
		}
		super.setFont(font);
	}

	@Override
	protected void drawText(Graphics2D g2d, Color color)
	{
		if (leftColor != null)
		{
			g2d.translate(-leftX, -leftY);
			super.drawText(g2d, leftColor);
			g2d.translate(leftX, leftY);
		}
		Color rColor = rightColor != null
				? rightColor
				: RThemeColor.colorSet.shadowColor;
		g2d.translate(rightX, rightY);
		super.drawText(g2d, rColor);
		g2d.translate(-rightX, -rightY);
		Color fColor = getForeground();
		if (fColor instanceof UIResource)
			fColor = color;
		super.drawText(g2d, fColor);
	}
}
